﻿//----------------------------------------------------------------------------------------------------
// IAction is the base class for actions that the player can/will/has performed.
//----------------------------------------------------------------------------------------------------
package HG.Actions
{
	import HG.Debug;
	import HG.GameService;
	
	import HG.Managers.PlayerManager;
	import HG.Managers.LevelManager;
	import HG.Managers.ActionManager;
	import HG.Managers.InventoryManager;
	
	import HG.Visual.VisualNode;
	

	
	public class ActionUnlock extends IAction
	{
		//----------------------------------------------------------------------------------------------------
		public function ActionUnlock(playerID:Number, nodeID:Number, type:Number)
		{
			super(playerID, nodeID, type);
		}
		
		//----------------------------------------------------------------------------------------------------
		public override function Execute():Boolean
		{
			var levelManager:LevelManager = GameService.GetInstance().GetLevelManager();
			var playerManager:PlayerManager = GameService.GetInstance().GetPlayerManager();
			var inventoryManager:InventoryManager = GameService.GetInstance().GetInventoryManager();
			
			var visNode:VisualNode = levelManager.GetVisualNode(m_nodeID);
			
			m_executeCount++;

			visNode.SetProgressDisplay(100, (GetOwner() == playerManager.GetCurrentPlayerID()));
			visNode.ClearPendingAction();
			
			inventoryManager.RemovePlayerEncryptionKey(m_playerID, visNode.GetEncryptionKey());
			
			visNode.SetEncryptionKey(0);

			return true;
		}
		
		//----------------------------------------------------------------------------------------------------
	}
}